﻿Type=Activity
Version=2.71
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

	Dim V_CLLBBM As String
	Dim V_CLLBMC As String
	Dim V_ZYH As String
	
	Dim FBHList As List
	Dim FCLLB As String
	'Dim FIndex As Int
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim lsvXM As ListView
	
	Dim HttpJobTool As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHList")
	
	InitLayOut
	
	Activity.Title = "病人列表-" & V_CLLBMC
	
End Sub

Sub Activity_Resume
	If FCLLB<>V_CLLBBM Then
		RefreshData
	Else
		SetYJBHList(FBHList)
		'lsvXM.GetItem(FIndex)
	End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitLayOut
	
	lsvXM.TwoLinesLayout.ItemHeight = 120
	lsvXM.TwoLinesLayout.Label.Top = 0
	lsvXM.TwoLinesLayout.Label.Height = 80
	lsvXM.TwoLinesLayout.SecondLabel.Top = 80
	lsvXM.FastScrollEnabled = True
	
	'高级菜单
	Activity.AddMenuItem("住院/门诊号","MenuItemAdv")
	'Activity.AddMenuItem("姓名","MenuItemAdv")
	'Activity.AddMenuItem("设置","MenuItemAdv")

	Activity.AddMenuItem("选择处理类别","MenuItemAdv")
End Sub


Sub lsvXM_ItemClick (Position As Int, Value As Object)
	Dim mapReVal As Map
	mapReVal = Value
	'FIndex = Position
	
	BHJCBGInfo.V_XB = mapReVal.Get("XB")
	BHJCBGInfo.V_XM = mapReVal.Get("XM")
	BHJCBGInfo.V_SQDH = mapReVal.Get("YJDH")
	BHJCBGInfo.V_BHID = mapReVal.Get("BHID")
	StartActivity("BHJCBGInfo") 
	
End Sub

Sub MenuItemAdv_Click
	If Sender = "住院/门诊号" Then
		V_ZYH = ""
		StartActivity("BHSearch") 
		
	Else If Sender = "选择处理类别" Then
		V_ZYH = ""
		StartActivity("SelectCLLB") 
	End If
	
End Sub

Sub RefreshData
	Dim sURL,sSession,sText,sCLLB As String
	
	Activity.Title = "病人列表-" & V_CLLBMC 
	lsvXM.Clear
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sCLLB = PublicVar.GV_DesTool.Base64encrypt(V_CLLBBM)
	
	sText = "Session=" & sSession & "&CLLB=" & sCLLB 

	sURL = PublicVar.GetServerUrl&"/getyjbhlist"

	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	
	ProgressDialogShow("正在获取数据，请稍候...")	

End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				LoginSuccess(Job)
      End If
   Else
		LoginError(Job)
   End If
   Job.Release
End Sub

Sub LoginSuccess(Job As HttpJob)  
	Dim sResult,sCode,sData As String
	Dim mapResult As Map
	
	ProgressDialogHide
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		'ToastMessageShow("获取数据失败"&CRLF &sResult, True)
		Msgbox("获取数据失败"&CRLF &sResult,"错误")
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		'ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Msgbox("返回的数据为空","错误")
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	PublicVar.GV_JSonTool.Initialize(sData)
	FBHList = PublicVar.GV_JSonTool.NextArray
	
	SetYJBHList(FBHList)
	FCLLB=V_CLLBBM
End Sub

Sub LoginError(Job As HttpJob)    
	Dim sMsg As String
	ProgressDialogHide
	
  Log("Error: " & Job.ErrorMessage)
	sMsg = "获取病人数据失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
End Sub

Sub SetYJBHList(lsRecords As List)
	Dim sLine1,sLine2,sZYH As String
	Dim mapResult As Map
	lsvXM.Clear
	
	For i = 0 To lsRecords.Size - 1 
		mapResult = lsRecords.Get(i)
		sZYH = mapResult.Get("ZYH")
		If V_ZYH<>"" Then
			If V_ZYH=sZYH Then
				sLine1 = mapResult.Get("XM") & " " & mapResult.Get("XB") & " "& mapResult.Get("JCMC") 
				
				sLine2 = mapResult.Get("SQRQ2") & " " & mapResult.Get("ZYH")

				lsvXM.AddTwoLines2(sLine1,sLine2,mapResult)			
			End If
		Else
			sLine1 = mapResult.Get("XM") & " " & mapResult.Get("XB") & " "& mapResult.Get("JCMC") 
			
			sLine2 = mapResult.Get("SQRQ2") & " " & mapResult.Get("ZYH")

			lsvXM.AddTwoLines2(sLine1,sLine2,mapResult)				
		
		End If
		
	Next

End Sub
